
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工列表</title>
</head>
	<h1>员工列表</h1>
		<?php 
			$link  = mysql_connect("localhost","root","root");
			if (!$link){
				die("数据库连接不成功");
			}
			mysql_query("set names utf8",$link) or die(mysql_errno());
			mysql_select_db("emp",$link) or die(mysql_errno());
			//加上分页
			$pageSize = 2;//一页显示多少条记录
			$rowCount = 0;//总共有多少条记录
			$pageNow = 1;
			$pageCount = 2;//总共多少页
			
			if(!empty($_GET['pageNow'])){
				$pageNow = $_GET['pageNow'];
			}
			
			
			$sql = "select count(id) from emp";
			
			$res1 = mysql_query($sql);
			if($row = mysql_fetch_row($res1)){
				$rowCount = $row[0];
			}
			
			$pageCount = ceil($rowCount/$pageSize);
			
			$beginRow = ($pageNow-1)*$pageSize;
			
			
			$sql = "select id,name,grade,email,salary from emp limit $beginRow,$pageSize";
			
			$res = mysql_query($sql);

			echo "<table border=\"1px\">";
			echo "	<tr>";
			echo "		<td>id</td>";
			echo "		<td>姓名</td>";
			echo "		<td>等级</td>";
			echo "		<td>Email</td>";
			echo "		<td>薪水</td>";
			echo "		<td>操作</td>";
			echo "	</tr>";
			
			while($row = mysql_fetch_assoc($res)){
				echo "<tr>";
				echo "<td>".$row['id']."</td>";
				echo "<td>".$row['name']."</td>";
				echo "<td>".$row['grade']."</td>";
				echo "<td>".$row['email']."</td>";
				echo "<td>".$row['salary']."</td>";
				echo "<td><a href='#'>修改</a>&nbsp;&nbsp;<a href='#'>删除</a></td>";
				echo "</tr>";
			}
			echo "	</table>";
					//页数索引
// 			for ($i = 1; $i <= $pageCount; $i++) {
// 				echo "<a href='empList.php?pageNow=$i'>$i</a> &nbsp;";
// 			}
			//上一页和下一页
			if($pageNow>1){
				$pagePre = $pageNow-1;
				echo "<a href='empList.php?pageNow=$pagePre'>上一页</a> &nbsp;";
			}
			if($pageNow<$pageCount){
				$pageNext = $pageNow+1;
				echo "<a href='empList.php?pageNow=$pageNext'>下一页</a> &nbsp;";
			}
			
			//当前页和总共页
			echo "当前是{$pageNow}页/共{$pageCount}页";
			//跳转到第n页
			mysql_free_result($res1);
			mysql_free_result($res);
			mysql_close();
		?>
		<br>跳转到
			<form action="empList.php">
				<input name="pageNow" type="text"> 
				<input type="submit" value="转到"/>
			</form>
			
</html>


	
	
	